<html>
<head>
    <meta charset="UTF-8">
    <title>登录窗口</title>
    <link rel="stylesheet" type="text/css" media="screen" href="/static/css/bootstrap.min.css">
</head>
<body>
<div class="container">
    <div class="row" style="margin-top: 80px">
        <div class="col-md-4 col-md-offset-4">
            <div class="panel panel-primary">
                <div class="panel-heading">注册用户</div>
                <div class="panel-body">

                    <!--						<form action="" method="post"  >-->
                    <div class="form-group">
                        <label for="userName">用户名</label>
                        <input type="text" id="ipt-username" name="userName"
                               class="form-control" placeholder="请输入用户名">
                    </div>
                    <div class="form-group">
                        <label for="password">密码</label>
                        <input type="password" id="ipt-pwd" name="password"
                               class="form-control"  placeholder="请输入密码"
                               value="" >
                    </div>
                    <div class="form-inline text-right">
                        <button id="btn-login" class="btn btn-primary">注册</button>
                    </div>
                    <!--						</form>-->
                </div>
            </div>
        </div>

    </div>

</div>
</body>
<script src="../static/js/axios.min.js"></script>
<script>
    document.getElementById('btn-login').onclick = function () {
        const userName = document.getElementById('ipt-username').value;
        const pwd = document.getElementById('ipt-pwd').value;
        const url = '/user/register';
        const data = {
            "username": userName,
            "password": pwd
        }
        axios.post(url
            , data).then(function (response) {
            if (response.data.code === 200){
                alert('注册成功');
                window.location = '/users/login.html';
            }else {
                alert('注册失败');
            }
        })
    }
</script>
</html>